/**
 * Copyright (c) 2019 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.manager;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.dao.SponsorMapper;
import org.xstgongyi.eduaid.dataobject.SponsorDO;

/**
 * @author oldcrane
 * @created 2019-04-24
 */
@Service
@CacheConfig(cacheNames = "sponsor")
public class SponsorManager {

	@Autowired
	private SponsorMapper sponsorDao;

	@CacheEvict(allEntries = true)
	public void insert(SponsorDO sponsor) {
		sponsorDao.insert(sponsor);
	}

	@CacheEvict(allEntries = true)
	public void update(SponsorDO sponsor) {
		sponsorDao.update(sponsor);
	}

	/**
	 * 调用者需保证参数不为null
	 */
	@Cacheable(key = "#id")
	public SponsorDO getById(Integer id) {
		return sponsorDao.getById(id);
	}

	public List<SponsorDO> listAll() {
		return sponsorDao.listAll();
	}

	/**
	 * 调用者需保证参数合法性，offset和limit为必填
	 */
	public List<SponsorDO> listPage(Map<String, Object> condition) {
		List<SponsorDO> sponsors = sponsorDao.listPage(condition);
		return sponsors;
	}

	/**
	 * 调用者需保证参数合法性
	 */
	public int countTotal(Map<String, Object> condition) {
		return sponsorDao.countTotal(condition);
	}

}
